var lengthOfLongestSubstring = function (s) {
  let map = new Map();
  let i = -1
  let res = 0
  let n = s.length
  for (let j = 0; j < n; j++) {
    if (map.has(s[j])) {
      i = Math.max(i, map.get(s[j]))
    }
    let res1 = j - i
    res = Math.max(res, res1)
    map.set(s[j], j)
  }
  return res
};
let str = 'nihaowohaodajiahmpo'
console.log(lengthOfLongestSubstring(str));